package onjava.advance.ch01.sec10;


import java.util.Random;

public enum Input {
    // 钱
    NICKEL(5),
    DIME(10),
    QUARTER(25),
    DOLLAR(100),
    // 商品
    TOOTHPASTE(200),
    CHIPS(75),
    SODA(100),
    SOAP(50),
    // 操作 退出交易
    ABORT_TRANSACTION {
        @Override
        int amount() {
            throw new RuntimeException("ABORT.amount()");
        }
    },
    // 操作 关闭机器
    STOP {
        @Override
        int amount() {
            throw new RuntimeException("SHUT_DOWN.amount()");
        }
    };
    int value;

    Input(int value) {
        this.value = value;
    }

    Input() {
    }

    int amount() {
        return value;
    }

    static Random rand = new Random(47);

    public static Input randomSelection() {
        return values()[rand.nextInt(values().length - 1)];
    }
}
